library UnitDie initializer init requires InitFunction, SystemInit, InitFilter, MonsterVo

    globals
        integer killCount = 0
    endglobals

    // ====================================================================

    // enemyDieConditions
    // 英雄杀敌要做的事情
    function killIncreasePropertyAction takes nothing returns nothing

        local integer uid = GetPlayerId(GetOwningPlayer(GetKillingUnit()))
        local unit u = GetKillingUnit()
        local unit bu = GetDyingUnit()

        // 杀敌增加属性

        // 装备的一些技能

        // 命运杀敌需要触发的一些函数

        set u = null
        set bu = null
    endfunction
    // ====================================================================

    // 英雄死亡
    // ====================================================================
    private function heroUnitDieConditions takes nothing returns boolean
        return (GetDyingUnit() == udg_player_select_hero[0]) or (GetDyingUnit() == udg_player_select_hero[1]) or (GetDyingUnit() == udg_player_select_hero[2]) or (GetDyingUnit() == udg_player_select_hero[3])
    endfunction
    private function heroUnitDieTrigger takes nothing returns nothing

        local trigger tri = CreateTrigger()
        call TriggerRegisterFriendlyUnitEventFF(tri, EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddCondition(tri, Condition(function heroUnitDieConditions))
        // call TriggerAddAction(tri, function heroUnitDieAction)
    endfunction
    // ====================================================================

    // ====================================================================

    // 攻家怪死亡
    private function player6DieAction takes nothing returns nothing
        
        local unit u = GetKillingUnit()
        local integer uid = GetPlayerId(GetOwningPlayer(u))
        local unit bu = GetDyingUnit()

        // 表示进攻怪
        if FF_GetTypeId(bu) > 10000 then
            // call MonsterVo_die(u, bu)
        endif

        set killCount = killCount + 1
        // call BJDebugMsg("killCount: " + I2S(killCount))
        call removeMonsterFromTable(uid, bu)
        call FF_DestroyUnitPro(bu)
        call RemoveUnit(bu)
    endfunction
    private function player6DieTrigger takes nothing returns nothing
        local trigger tri = CreateTrigger()
        call TriggerRegisterPlayerUnitEvent(tri, Player(PID_GAME_MONSTER), EVENT_PLAYER_UNIT_DEATH, null)
        call TriggerAddAction(tri, function player6DieAction)
        set tri = null
    endfunction
    // ====================================================================



    function allUnitDieAction takes nothing returns nothing
        local integer uid = GetPlayerId(GetOwningPlayer(GetKillingUnit()))
        local unit u = GetKillingUnit()
        local unit bu = GetDyingUnit()



        set u = null
        set bu = null
    endfunction

    // 所有单位死亡执行，做一些清空值的操作
    function allUnitDieTrigger takes nothing returns nothing
        local trigger tri = CreateTrigger()

        call TriggerRegisterAnyUnitEventBJ( tri, EVENT_PLAYER_UNIT_DEATH )
        call TriggerAddAction(tri, function allUnitDieAction)
    endfunction

    
    private function init takes nothing returns nothing
        // 怪物死亡增加属性
        // =========================================================================
        local trigger unitDieTri = CreateTrigger()
        call TriggerRegisterEnemyUnitEventFF(unitDieTri, EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddCondition(unitDieTri, Condition(function enemyDieConditions))
        // 英雄杀敌增加属性
        call TriggerAddAction(unitDieTri, function killIncreasePropertyAction)
        // =========================================================================

        // 英雄死亡业务
        // call heroUnitDieTrigger()
        // 所有单位死亡
        call allUnitDieTrigger()
        // 攻家怪死亡
        call player6DieTrigger()
    endfunction
endlibrary
